package com.jeasonzhao.report.engine.impl;

import com.jeasonzhao.commons.json.JSONClass;
import com.jeasonzhao.commons.json.JSONException;
import com.jeasonzhao.commons.logger.Logger;
import com.jeasonzhao.commons.utils.Algorithms;
import com.jeasonzhao.report.dataset.DataSet;
import com.jeasonzhao.report.exceptions.DataSetGenerateException;

public class ExcelDataSetProvider extends AbstractDataSetProvider
{
    public ExcelDataSetProvider()
    {
    }

    private final static String HelpMessage =
        "Configuration error, the configration code snippet must be:"
        + "{file:<FileName>;sheet:[SheetName]}";
    public DataSet getDataSet(Logger log,int nPageSize,int nCurrentPageNo)
        throws DataSetGenerateException
    {
        if(null == this.report)
        {
            return null;
        }
        String strDataSource = this.report.getDataSetProvider();
        if(Algorithms.isEmpty(strDataSource))
        {
            throw new DataSetGenerateException(HelpMessage);
        }
        JSONClass cls = null;
        try
        {
            cls = JSONClass.from(strDataSource);
        }
        catch(JSONException ex)
        {
            throw new DataSetGenerateException(HelpMessage,ex);
        }
        String fileName = cls.valueOf("file","filename");
//        String sheetName = cls.valueOf("sheet","sheetname","page");
        if(Algorithms.isEmpty(fileName))
        {
            throw new DataSetGenerateException(HelpMessage);
        }
        //Read data from excel.
        /**
         * @todo implement read data from excel.
         */
        return null;
    }

}
